import { Context } from 'koa';
import { ResponseUtil } from '../utils/response';

export const notFoundHandler = async (ctx: Context, next: () => Promise<void>) => {
  try {
    await next();
  } catch {
    // 如果没有错误但也没有路由，则返回404
    if (ctx.status === 404) {
      ctx.status = 404;
      ctx.body = ResponseUtil.error(ctx, `Route ${ctx.path} not found`, 'NOT_FOUND', 404);
    }
  }
};